<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{padding: 0;margin: 0;}
        .shadow{
            width: 200px;
            height: 200px;
            background-color: rgba(0,0,0,0.5);
            position: absolute;
            left:0;
            top:0;
        }
    </style>
</head>
<body>
    <div class="shadow"></div>
</body>
<script>
    // 需求: 盒子跟随鼠标移动
    // 1. 需要知道鼠标每次移动时的位置
    // 2. 盒子如何跟随鼠标移动 => 调整盒子的位置(margin position )

    var shadow = document.getElementsByClassName("shadow")[0];

    document.onmousemove = function(e){
        var e = e || window.event;

        var x = e.pageX;
        var y = e.pageY;

        // 取值时记得去单位, 赋值时记得加单位
        shadow.style.left = x + "px";
        shadow.style.top = y + "px";

    }




</script>
</html>